package org.example.service.imp;

import org.example.bean.GradeBean;
import org.example.bean.UserBean;
import org.example.mapper.IUserMapper;
import org.example.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class UserServiceImp implements IUserService {
    @Autowired
    private IUserMapper mapper;
    @Override
    public UserBean login(String userName, String passWord) {
        return mapper.login(userName, passWord);
    }

    @Override
    public boolean isGradeByID(Integer userID, String gradeName) {
        List<GradeBean> list = mapper.isGradeByID(userID, gradeName);
        return list.size() != 0;
    }

    @Override
    public void add(UserBean userBean, List<Integer> gradeList) {
        mapper.add(userBean);
        mapper.addGrade(userBean.getId(), gradeList);
    }

    @Override
    public UserBean findByID(Integer userID) {
        return mapper.findByID(userID);
    }

    @Override
    public void update(Integer userID, List<Integer> newGradeList) {
        mapper.del(userID);
        mapper.addGrade(userID,newGradeList);
    }
}
